#include "bluso_lib.h"


#include "script_lua.h"


int script_init()
{
    bin_script_init();
    lua_script_init();
}

#define B_F_AS_EXT( ext ) ( fnlength >= strlen(ext) && strcmp( filename, ext ) )

int script_load( char* filename )
{
    
    int fnlength = strlen(filename,255)
    
    if ( fnlength == 255 ) {
        return -100;
    }
    
    if B_F_AS_EXT(".so") {
        return bin_script_load( filename, fnlength );
    }
    
    if B_F_AS_EXT(".lua") {
        return lua_script_load( filename, fnlength );
    }
    
    return -101;
}

int script_thread_load( void** p )
{
    return lua_thread_load( void** p );
}


typedef int (*com_call)( void* com, void* args, paratype* rsttype, void** rst );

struct stt_com_function{
    char name[255];
    
    void* com;
    com_call call;
    
    int argc;
    int argtypes[255];
    int rsttype;
}

typedef stt_com_function com_func;

int script_com_load(char* filename)
{
    
    int fnlength = strlen(filename,255)
    
    if ( fnlength == 255 ) {
        return -100;
    }
    
    if B_F_AS_EXT(".so") {
        return bin_script_load( filename, fnlength );
    }
    
    if B_F_AS_EXT(".lua") {
        return lua_script_load( filename, fnlength );
    }
    
    return -101;
    
}

int com_function_call( com_func* func, int argc, paratype *argtypes, void *args, paratype* rsttype, void** rst )
{
    return func->call( com, args, rsttype, rst );    
}